<?php
$array=array(1,2,3,4);
$res=extract($array);
var_dump($res);


//comact 用给定的变量名创建一个新函数
$firstname = "Bill"; $lastname = "Gates"; $age = "60"; $result = compact("firstname", "lastname", "age"); print_r($result);
/*
 *  Array ( [firstname] => Bill [lastname] => Gates [age] => 60 )
 */

//array_chunk 可以将一个数组分成多个,ture为保留原数组的键名
$arr=array(1,2,3,4);
$arr=array_chunk($arr,3,TRUE);
p($arr);
/*
 * array(2) {
  [0]=>
  array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
  }
  [1]=>
  array(1) {
    [3]=>
    int(4)
  }
}
 */

//array_walk($arr,'function','words');

$words=array("l"=>"lemon","o"=>"orange","b"=>"banana","a"=>"apple");
//定义一个回调函数，输出数组元素
function words_print($value,$key,$prefix){
    echo "$prefix:$key=>$value<br>\n";
}
//定义一个回调函数直接改变元素的值
function words_alter(&$value,$key){
    $value=ucfirst($value);
    $key=strtoupper($key);
}
//输出元素的值
array_walk($words,'words_print','words');
/*
 * words:l=>lemon
words:o=>orange
words:b=>banana
words:a=>apple

 */
//改变元素的值
array_walk($words,'words_alter');
echo "<pre>";
print_r($words);
echo "</pre>";
/*
 * Array
(
    [l] => Lemon
    [o] => Orange
    [b] => Banana
    [a] => Apple
)
 */
function p($res){
    echo "<pre>";
    var_dump($res);
    echo "</pre>";
}

?>